#!/usr/bin/ruby
version = File.readlines('version_number').join.split('.')
rewrite		= version[0].to_i
core_major	= version[1].to_i
core_minor	= version[2].to_i
plug_major	= version[3].to_i
plug_minor	= version[4].to_i
plug_count	= version[5].to_i

# Core major
puts "Showing you the SVN stats..."
system('svn status')
puts "Current version is #{version.join('.')}"
passed = false
while !passed
	print 'Has there been a major change to the core files and plugins? Y/N '
	result = gets.chomp.downcase
	passed = true
	if result == 'y' then
		core_major += 1
	elsif result == 'n' then
		passed = true
	else
		passed = false
	end
end
# Core minor
passed = false
while !passed
	print 'Has there been a minor change to the core files and plugins? Y/N '
	result = gets.chomp.downcase
	passed = true
	if result == 'y' then
		core_minor += 1
	elsif result == 'n' then
		passed = true
	else
		passed = false
	end
end
# Plugin major
passed = false
while !passed
	print 'Has there been a major change to the other plugins? Y/N '
	result = gets.chomp.downcase
	passed = true
	if result == 'y' then
		plug_major += 1
	elsif result == 'n' then
		passed = true
	else
		passed = false
	end
end
# Plugin minor
passed = false
while !passed
	print 'Has there been a minor change to the other plugins? Y/N '
	result = gets.chomp.downcase
	passed = true
	if result == 'y' then
		plug_minor += 1
	elsif result == 'n' then
		passed = true
	else
		passed = false
	end
end
# Checking plugin count
puts "Checking plugin count..."
current_count = Dir['./lib/plugins/*.rb'].count
if current_count != plug_count then
	puts "Plugin count is different, and is now at #{current_count}."
	plug_count = current_count
else
	puts "Plugin count is the same."
end
puts "New version number is #{rewrite}.#{core_major}.#{core_minor}.#{plug_major}.#{plug_minor}.#{plug_count}, writing that to the disk."
File.open('version_number','w') do |file|
	file << "#{rewrite}.#{core_major}.#{core_minor}.#{plug_major}.#{plug_minor}.#{plug_count}"
end
passed = false
while !passed
	print 'Going to commit? Y/N '
	result = gets.chomp.downcase
	passed = true
	if result == 'y' then
		system('svn ci')
	elsif result == 'n' then
		passed = true
	else
		passed = false
	end
end
